--明略
local minglue = fk.CreateSkill {
    name = "mcdh_minglue",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

minglue:addEffect(fk.CardUsing,{
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) and target == player then
            return true
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room

    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if player.phase == Player.Play then
            local targets = self.cost_data[1]
            local cards = self.cost_data[2]
            room:addPlayerMark(player,"#zhongxinggongbei_re-turn",#cards)
            local  targets = lib.SortPlayId(room,targets,room:getPlayerById(targets[1]))
            player:showCards(cards)
            table.forEach(room.players, function(p) room:fillAG(p, cards) end)
            for _, pid in ipairs(targets) do
                local p = room:getPlayerById(pid)
                if not (p.dead or p:isNude()) then
                    local card = room:askForCard(p,1,1,true,self.name,false,".","#zhongxinggongbei:"..player.id)
                    room:moveCards({
                        ids = card ,
                        from = p.id,
                        to = player.id,
                        toArea = Card.PlayerHand,
                        moveReason = fk.ReasonGive,
                        skillName =  self.name,
                        moveVisible = false
                    })
                    --交给后检测一遍牌是否在手上
                    cards = table.filter(cards, function(id) return room:getCardOwner(id) == player and room:getCardArea(id) == Card.PlayerHand end)
                    if #cards ~= 0 then
                        local chosen = room:askForAG(p, cards, false, self.name)
                        room:takeAG(p, chosen, room.players)
                        room:obtainCard(p ,chosen, true, fk.ReasonPrey)
                        table.removeOne(cards, chosen)
                    end
                end
                --检测牌是否还在手里
                cards = table.filter(cards, function(id) return room:getCardOwner(id) == player and room:getCardArea(id) == Card.PlayerHand end)
                if #cards == 0 then break end
            end
            table.forEach(room.players, function(p) room:closeAG(p) end)
        else
            room:recastCard(self.cost_data, player, self.name)
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_minglue"] = "明略",
    [":mcdh_zhouxuanyuli"] = "当你使用伤害牌时，你声明此牌是否造成伤害，若结果与你声明相同，你可以令一名角色将一张牌交给另一名角色。",
    ["#zhouxuanyuli-show"]  ="周旋与礼:展示任意张手牌并选择等量名角色,令这些角色依次交给你一张牌并获得你展示的一张牌",
    ["#zhouxuanyuli-targets"] = "周旋与礼:选择 %arg 名角色(第一个点击的为起始角色)",
    ["#zhongxinggongbei"] = "周旋与礼:交给 %src 一张牌并获得其展示的一张牌",
    ["#zhouxuanyuli-recast"] = "周旋与礼: 重铸 %arg 张牌",
}

return minglue